Manage areas
GeoManager
Manage areas.
class yandex_b2b_go.geo.GeoManager
Attribute
-
ZoneInfoManager — zone management.
zoneinfo: ZoneInfoManager
Methods
- list — gets information about all the available ride areas for the user.
- create — creates a new area of user rides.
- update — changes the user's ride area.
- delete — deletes the user's ride area.
List
Gets information about all the available ride areas for the user.
async def list(
limit: Optional[int] = None,
offset: Optional[int] = None
) -> GeoRestrictionsListResponse
Parameters
limit— number of records to display. If this parameter is not specified, information about the first 100 records is returned.offset— number of skipped records. If this parameter is missing, information is returned starting from the first record.
If successful, returns the GeoRestrictionsListResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import GeoManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
geo_manager = GeoManager(client=client)
try:
geos = await geo_manager.list(
limit=10,
)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Create
Creates a new ride area for the user.
async def create(geo_restrictions: GeoRestrictions) -> GeoRestrictionsResponse
Parameter
geo_restrictions— new area parameters. Class GeoRestrictions.
If successful, the GeoRestrictionsResponse class is returned.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import GeoManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
geo_manager = GeoManager(client=client)
try:
geo_restrictions = typing.GeoRestrictions(
geo_type=typing.Geo.circle,
name='Офис 2',
geo=typing.GeoCircle(
lat=37.642639,
lon=37.642639,
radius=200
)
)
geo_id = await geo_manager.create(
geo_restrictions=geo_restrictions
)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Update
Changes the user's ride area.
async def update(geo_id: str, geo_restrictions: GeoRestrictions) -> GeoRestrictionsResponse:
Parameters
geo_id— area ID.geo_restrictions— new area parameters, class GeoRestrictions.
If successful, the GeoRestrictionsResponse class is returned.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import GeoManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
geo_manager = GeoManager(client=client)
try:
geo_restrictions = typing.GeoRestrictions(
geo_type=typing.Geo.circle,
name='Office 2',
geo=typing.GeoCircle(
lat=37.642639,
lon=37.642639,
radius=200
)
)
geo_id = await geo_manager.update(
geo_id='b45e...f0de',
geo_restrictions=geo_restrictions
)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Delete
Deletes the user's ride area.
async def delete(geo_id: str) -> GeoRestrictionsResponse:
Parameter
geo_id— area ID
If successful, the GeoRestrictionsResponse class is returned.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import GeoManager
from yandex_b2b_go import errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
geo_manager = GeoManager(client=client)
try:
geo_id = await geo_manager.delete(
geo_id='b45e...f0de',
)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
ZoneInfoManager
Manage zones.
class yandex_b2b_go.geo.ZoneInfoManager
Method
- get — gets information about the zone the point belongs to.
Get
Gets information about the zone the point belongs to.
async def get(lat: float, lon: float) -> ZoneInfoResponse
Parameters
lat— latitude of a point in the zone.lon— longitude of a point in the zone.
If successful, the ZoneInfoResponse class is returned.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import GeoManager
from yandex_b2b_go import errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
geo_manager = GeoManager(client=client)
try:
zone_info = await geo_manager.zoneinfo.get(
lat=32.093320,
lon=34.798363,
)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())